<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class NoticesUsers extends Model
{
    const ISREAD=1; //已读
    const NOREAD=0; //未读


    /**
     * 读取通知
     * @param $user
     * @param $id
     * @return NoticesUsers
     */
    public static function readNotice($user,$id)
    {
       return NoticesUsers::where('users_id',$user)
            ->where('notice_id',$id)
            ->update(['is_read'=>self::ISREAD]);
    }

    /**
     * 删除通知
     * @param $user
     * @param $id
     * @return bool
     */
    public static function deleteNotice($user,$id)
    {
        return NoticesUsers::where('users_id',$user)
            ->whereIn('notice_id',$id)
            ->delete();
    }

    public function notice()
    {
        return $this->hasOne(Notices::class,'id','notice_id');
    }
}
